//
//  GuideVC.m
//  Run
//
//  Created by 男哥呵呵 on 16/4/15.
//  Copyright © 2016年 BetaTheta. All rights reserved.
//

#import "GuideVC.h"

@interface GuideVC ()<UIScrollViewDelegate>

@property (strong, nonatomic) IBOutlet UIScrollView *scorllView;
@property (strong, nonatomic) UIPageControl *pageC;
@property (strong, nonatomic) UIButton *endBtu;

@end

@implementation GuideVC

- (instancetype)initWithPicArr:(NSArray *)picArray {
    
    self = [super init];
    if (self) {
        self.picArr = [NSArray arrayWithArray:picArray];
    }
    return self;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.view.backgroundColor = [UIColor whiteColor];
    self.scorllView.contentSize = CGSizeMake(self.picArr.count * SCREENWIDTH, 0);
    self.scorllView.pagingEnabled = YES;
    self.scorllView.showsHorizontalScrollIndicator = NO;
    self.scorllView.showsVerticalScrollIndicator = NO;
    self.scorllView.bounces = NO;
    
    for (int i = 0; i < self.picArr.count; i++) {
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(SCREENWIDTH * i, 0, SCREENWIDTH, SCREENHEGITH)];
        imageView.image = [UIImage imageNamed:self.picArr[i]];
        [self.scorllView addSubview:imageView];
        
    }
    
    [self createPage];
    [self createEndBtu];
}

- (void)createEndBtu {
    
    self.endBtu = [UIButton buttonWithType:UIButtonTypeSystem];
    self.endBtu.frame = CGRectMake(SCREENWIDTH * (self.picArr.count - 1), self.pageC.frame.origin.y - 40, SCREENWIDTH, 30);
    [self.endBtu addTarget:self action:@selector(endAction:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.endBtu setTitle:@"立即进入" forState:UIControlStateNormal];
    [self.endBtu setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
    [self.scorllView addSubview:self.endBtu];
    
}

- (void)endAction:(UIButton *)sender {
    
    [[NSUserDefaults standardUserDefaults] setObject:@"yes" forKey:@"Guide"];
    [self.delegate endGuide];
    
    
}

- (void)createPage {
    
    self.pageC = [[UIPageControl alloc] initWithFrame:CGRectMake(0, 0, 0, 30)];
    self.pageC.center = CGPointMake(SCREENWIDTH / 2, SCREENHEGITH - 40);
    self.pageC.numberOfPages = self.picArr.count;
    [self.view addSubview:self.pageC];
}

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    
    self.pageC.currentPage = self.scorllView.contentOffset.x / SCREENWIDTH;
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
